package net.gz01.wallet.web.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Page;

import net.gz01.wallet.common.ZOSearchCondition;
import net.gz01.wallet.common.ZOSqlHelper;
import net.gz01.wallet.web.model.base.BaseHelpInfo;


@SuppressWarnings("serial")
public class HelpInfo extends BaseHelpInfo<HelpInfo> {
    public static final HelpInfo dao = new HelpInfo().dao();

    public Page<HelpInfo> search(ZOSearchCondition sc){
        int pageNumber = sc.page.getPageNum();
        int pageSize = sc.page.getNumPerPage();

        ZOSqlHelper sql = new ZOSqlHelper(" from help_info WHERE 1 = 1");
        sql.equals("type", sc.get("helpType"));
        sql.equals("title", sc.get("title"));
        sql.like("editor", sc.get("editor"));
        String createTimeStart = sc.getStr("createTimeStart");
        String createTimeEnd = sc.getStr("createTimeEnd");
        String updateTimeStart = sc.getStr("updateTimeStart");
        String updateTimeEnd = sc.getStr("updateTimeEnd");
        sql.date("createTime", createTimeStart, createTimeEnd);
        sql.date("updateTime", updateTimeStart, updateTimeEnd);
        sql.orderBy("createTime", "desc");
        return super.paginate(pageNumber, pageSize, "select *", sql.toString(),sql.getParams());
    }

    public List<HelpInfo> selectHelpType(){
        List<HelpInfo> list = super.find("SELECT DISTINCT type FROM help_info");
        return list;
    }

    public List<HelpInfo> selectHelpTitle(){
        List<HelpInfo> list = super.find("SELECT id,title FROM help_info");
        return list;
    }

    public List<HelpInfo> selectHelpTitleByType(String type){
        List<HelpInfo> list = super.find("SELECT id,title FROM help_info where type = ?",type);
        return list;
    }

    public List<HelpInfo> selectHelpTitleByKeyWord(String keyword){
        String paraKeyWord = "%"+keyword+"%";
        List<HelpInfo> list = super.find("SELECT id,title FROM help_info where title like ? or content like ?",paraKeyWord,paraKeyWord);
        return list;
    }
}
